using System;
using System.Collections.Generic;
using System.Text;
using Castle.ActiveRecord;

namespace ElevatorSpeeches.Framework
{
	[ActiveRecord]
	public class Noun : EntityBase<Noun>
	{
        [Property]
        [ValidateNotEmpty]
        public string Body
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the given noun object if it exists, otherwise creates one.
        /// </summary>
        /// <param name="NounBody">The noun body.</param>
        /// <returns></returns>
		public static Noun GetOrCreate(string NounBody)
		{
			Noun noun = Noun.FindFirst(new NHibernate.Expression.EqExpression("Body", NounBody));
			if (noun != null)
			{
				return noun;
			}
			else
			{
				noun = new Noun();
				noun.Body = NounBody;
				noun.Save();				
				return noun;
			}
		}
	}
}
